<template>
  <view class="vision">
    <view class="container">
      <scroll-view class="box">
        <view style="height: 30rpx;background-color: #eee;"></view>
        <view class="text">温馨提示：你当前浏览的是{{ props.nickName }}_第{{ props.times }}次评估_{{ props.createTime }}_深圳附属华南医院</view>
        <view class="report">
          <view class="title">获取病例数据</view>
          <view class="list">STEADI评分<text class="riskData"></text></view>
          <view class="list">自评得分<text class="riskData">{{ state.score }}</text></view>
          <view class="list">步态和肌力或平衡是否存在问题<text class="riskData">{{ state.balance }}</text></view>
          <view class="list">跌倒风险等级
            <text class="riskData1" v-if="state.score>4">{{ state.riskLevel }}</text>
            <text class="riskData2" v-else>{{ state.riskLevel }}</text>
          </view>
          <view style="height: 3rpx;background-color: #eee;"></view>
          <view class="listFather">存在的问题
            <view class="listContainer" v-if="isView">
              <view class="listChild">1.视力评估：<text class="content">{{ state.vision }}</text></view>
              <view class="listChild">2.移动能力评估：<text class="content">{{ state.balanceList }}</text></view>
              <view class="listChild">3.跌倒风险药物评估：<text class="content">{{ state.medicine }}</text></view>
              <view class="listChild">4.直立型低血压评估：<text class="content">{{ state.lowBloodPressure }}</text></view>
              <view class="listChild">5.钙元素摄取评估：<text class="content">{{ state.calcium }}</text></view>
              <view class="listChild">6.足部和鞋子评估：<text class="content">{{ state.foot }}</text></view>
              <view class="listChild">7.基础疾病评估：<text class="content">{{ state.underlyingDisease }}</text></view>
              <view class="listChild">8.增加跌倒风险症状的评估：<text class="content">{{ state.symptom }}</text></view>
            </view>
            <view @tap="notShow" style="text-align: center;margin-bottom: 20rpx;" v-if="(isView)">收起</view>
            <view @tap="isShow" style="text-align: center;margin-bottom: 20rpx;" v-else>展开</view>
          </view>
        </view>
        <view class="method">
          <view class="title1">干预处方</view>
          <view style="height: 3rpx;background-color: #eee;"></view>
          <view class="listContainer1" v-if="isViewMethod" >
            <!-- <navigator
              :url="`/pages/fallRiskReports/components/fallIntervention/fallIntervention?id=${intervention.id}`"
              open-type="navigate"
              hover-class="none"
            > -->
            <view class="methodsListChild" v-for="(intervention,index) in state.intervention" :key="index" @tap="goInterventions(intervention.id)">
              {{ index+1 }}.{{ intervention.title }}
            </view>
            <!-- <view class="methodsListChild">2.移动能力评估：</view>
            <view class="methodsListChild">3.跌倒风险药物评估：</view>
            <view class="methodsListChild">4.直立型低血压评估：</view>
            <view class="methodsListChild">5.钙元素摄取评估：</view>
            <view class="methodsListChild">6.足部和鞋子评估：</view>
            <view class="methodsListChild">7.基础疾病评估：</view>
            <view class="methodsListChild">8.增加跌倒风险症状的评估：</view> -->
          </view>
          <view @tap="methodNotShow" style="text-align: center;margin-bottom: 20rpx;margin-top: 20rpx;font-weight: bold;font-size: 27rpx;" v-if="(isViewMethod)">收起</view>
          <view @tap="methodIsShow" style="text-align: center;margin-bottom: 20rpx;margin-top: 20rpx;font-weight: bold;font-size: 27rpx;" v-else>展开</view>
        </view>
        <view style="height: 150rpx;background-color: #fff;"></view>
      </scroll-view>
    </view>
  </view>
</template>

<script setup lang="ts">
import {ref,reactive} from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {getUserHistoryApi} from '@/apis/userHistory/userHistory'
import {getAllInterventionApi,getInterventionDetailsApi,putUpdateInstitutionApi} from '@/apis/intervention/intervention'
import {useMarkStore} from '@/stores/modules/mark'
const useMark = useMarkStore()
const props = defineProps({
  mark: String,
  times: String,
  createTime:String,
  nickName :String
})
const isView = ref(false)
const isShow = ()=>{
  isView.value= true
  console.log(isView.value)
}
const notShow = ()=>{
  isView.value= false
}
const isViewMethod = ref(false)
const methodIsShow = ()=>{
  isViewMethod.value= true
  console.log(isViewMethod.value)
}
const methodNotShow = ()=>{
  isViewMethod.value= false
}
const getReportDetails = async()=>{
  console.log(props.mark)
  console.log(props.times)
  console.log(props.createTime)
  console.log(props.nickName)
  const res = await getUserHistoryApi(props.mark)
  state.report = res.data
  console.log(state.report)
  console.log(state.report.medicine)
  state.medicine = state.report.medicine.join(';')
  state.foot = state.report.foot.join(';')
  state.underlyingDisease = state.report.underlyingDisease.join(';')
  state.symptom = state.report.symptom.join(';')
  state.lowBloodPressure = state.report.lowBloodPressure===1? "具有直立型低血压":"无";
  state.calcium = state.report.calcium.result===1? "缺钙" : "无";
  state.vision = state.report.visionReportVo.content.join(';')
  state.balanceList = state.report.balanceReportVo.balanceList.join(';')
  state.balance = state.report.balance===1? "是":"否";
  state.score = state.report.score
  state.riskLevel = state.report.score>4? "有风险":"无风险";
}
const getAllIntervention = async ()=>{
  const res = await getAllInterventionApi(props.mark)
  state.intervention = res.data
  console.log(state.intervention)
}
const state = reactive({
  report:{},
  medicine:[],
  foot:[],
  underlyingDisease:[],
  symptom:[],
  lowBloodPressure:'',
  calcium:'',
  vision:[],
  balanceList:[],
  riskLevel:'',
  balance:'',
  score:'',
  intervention:[]
})
onLoad(()=>{
  getReportDetails(),
  getAllIntervention()
})

const goInterventions =async (id)=>{
  const res =await putUpdateInstitutionApi(props.mark,id)
  console.log('一次测评的mark:',props.mark)
  console.log('存到本地的mark：',useMark.mark)
  console.log('put干预措施',res.code)
  console.log('put干预措施',res.msg)
  let url = `/pages/fallRiskReports/components/fallIntervention/fallIntervention?id=${id}`
  uni.navigateTo({
    url:url
  })
}
</script>

<style lang="scss">
page {
  background-color: rgb(10,127,255);
}
.vision{
  height:100vh;
  position: relative;
  .container{
  height: 95vh;
  margin: 30rpx;
  border-radius: 25rpx;
  background-color: #fff;
  .box{
   background-color: #fff;
.text{
  color: red;
  margin: 25rpx;
  font-size: 25rpx;
}
.report{
  margin: 20rpx;
  background-color: rgb(240,247,255);
  border-radius: 15rpx;
  position: relative;
  .riskData{
    position: absolute;
    left: 500rpx;
    font-size: 28rpx;
    font-weight: bold;
    color: rgb(10,127,255);
  }
  .riskData1{
    position: absolute;
    left: 500rpx;
    font-size: 28rpx;
    font-weight: bold;
    color: red;
  }
  .riskData2{
    position: absolute;
    left: 500rpx;
    font-size: 28rpx;
    font-weight: bold;
    color: rgb(9,191,98);
  }
  .title{
    padding-top: 15rpx;
    text-align: center;
    font-weight: bold;
    color:rgb(10,127,255);
    font-size: 32rpx;
  }
  .list{
    padding: 10rpx;
    margin: 15rpx;
    line-height: 25rpx;
    font-weight: bold;
    color: black;
    font-size: 28rpx;
  }
  .listFather{
    padding: 10rpx;
    margin: 15rpx;
    font-weight: bold;
    color: black;
    font-size: 28rpx;
    .listContainer{
      line-height: 15rpx;
      .listChild{
        padding-bottom: 10rpx;
        margin-top: 15rpx;
        line-height: 35rpx;
        color: black;
        font-weight: bold;
        font-size: 28rpx;
        .content{
          font-weight: 400;
          font-size: 27rpx
        }
  }
    }
  }
}
.method{
  margin: 20rpx;
  background-color: rgb(240,247,255);
  border-radius: 15rpx;
  .title1{
    padding-top: 15rpx;
    text-align: center;
    font-weight: bold;
    color:rgb(10,127,255);
    font-size: 32rpx;
  }
  .listContainer1{
    line-height: 15rpx;
    .methodsListChild{
        padding-bottom: 10rpx;
        margin-top: 15rpx;
        line-height: 35rpx;
        color: rgb(29,154,228);
        font-weight: bold;
        font-size: 28rpx;
    }
  }
}
  }
}
}
</style>